import QtQuick 2.0
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.3
import ConfigElementType 1.0

BasicArrayRow{
    property bool arrayItemAddRemovable: true

    property string __identifierProperty: ""

    function init()
    {
        objEditorLoader.source = "ObjectEditor.qml"
        connRowIndexChanged.target = rowModel
        var identifierProperty = configModel.idendifierProperty()
        if(identifierProperty !== ""){
            __identifierProperty = identifierProperty
            btnObjIdentifier.updateText()
            configModel.connectNotifySignal(__identifierProperty, btnObjIdentifier, "updateText")
        }
    }

    Button{
        id: btnObjIdentifier
        text: "Show"
        implicitWidth: 200
        onClicked: {
            objEditorPopup.open()
        }

        function updateText(){
            var identifierValue = configModel.getConfig(__identifierProperty)
            text = identifierValue === "" ? "Show" : identifierValue
        }
    }

    Popup{
        id: objEditorPopup

        anchors.centerIn: Overlay.overlay

        contentItem: Loader{
            id: objEditorLoader
            onLoaded: {
                item.sectionName = "Obj" + index
                item.configModel = configModel
                item.listMaxWidth = 1300
                item.listMaxHeight = 700
                item.arrayItemAddRemovable = arrayItemAddRemovable
                indexBinding.target = item
                item.init()
            }
        }

        width: contentWidth + 20
        height: contentHeight + 20

        Binding{
            id: indexBinding

            target: null
            value: "Obj " + index
            property: "sectionName"
        }
    }
}
